/**
 * created the 5 oct. 07
 */
package choco.global.scheduling.trees;

import choco.global.scheduling.trees.abstrees.AbstractNodeInfo;
import choco.global.scheduling.trees.abstrees.InternalNode;
import choco.global.scheduling.trees.abstrees.Leaf;



/**
 * @author Arnaud Malapert (arnaud.malapert@emn.fr)
 *
 */
public class CumNodeInfoT extends AbstractNodeInfo {

	/**
	 * 
	 */
	public CumNodeInfoT() {
		super(new int[1],new long[2]);
	}

	public void setCapacity(int capacity) {
		intValues[0]=capacity;
	}
	@Override
	public void reset(Leaf leaf, boolean ectOrLst) {
		this.reset(0, false, ectOrLst);
	}

	@Override
	public void reset(InternalNode node, boolean ectOrLst) {
		this.reset(0, false, ectOrLst);
		
	}

	@Override
	public void toDotCells(StringBuilder buffer) {
		toDotCell(buffer, "theta", longValues[0],longValues[1]);
		
	}

	@Override
	public void update(Leaf leaf, boolean ectOrLst) {
		this.longValues[0]=intValues[0]*leaf.getTaskVar().getInf()+leaf.getConsumption();
		this.longValues[1]=leaf.getConsumption();
	}

	
	@Override
	public void update(InternalNode node, boolean ectOrLst) {
		if(ectOrLst) {updateCECT(node);}
		else {updateCLST(node);}
		updateLongSum(node, 1);
			
	}
	/**
	 * update Time for ECT tree.
	 * @param node the node to update
	 */
	private void updateCECT(InternalNode node) {
		AbstractNodeInfo left=node.getLeftChild().infos;
		AbstractNodeInfo right=node.getRightChild().infos;
		this.longValues[0]=Math.max(right.getLongValue(0), left.getLongValue(0)+right.getLongValue(1));
	}
	/**
	 * update Time for LST tree.
	 * @param node the node to update
	 */
	private void updateCLST(InternalNode node) {
		//TODO arbre symetrique pour la cumulative
		System.err.println("fail : not yet implemented");
		System.exit(1);
	}
}
